A virtual machine (VM) is a software implementation of a machine (e.g., a computer) that executes programs like a physical machine. Multiple VMs each running on their own operating system (called the guest OS). The guest OSs do not have to be compliant with the hardware making it possible to run different OSs on the same computer, and the guest OSs may share the virtualized hardware resources. A hypervisor, also known as a virtual machine monitor (VMM), is a piece of computer software, firmware or hardware that creates and runs VMs in virtualization environment. A computer on which a hypervisor is running one or more VMs is defined as a host machine. Each virtual machine is called a guest machine. The hypervisor presents the guest OSs with a virtual operating platform and manages the execution of the guest OSs.
A CPU core is in host mode when the hypervisor runs on it and in guest mode when a VM runs on it. A CPU core stays in guest mode until any event, for example such as an interrupt from I/O device(s), timer or other event(s), configured to force a transition into host mode. When transitioning to host mode, the hypervisor takes over, handles the triggering event, delivers the interrupt to the corresponding interrupt handler of the targeted VM, and then re-enters guest mode to resume the VM's execution. When the corresponding interrupt handler associated with the interrupt completes, it acknowledge with an end of interrupt (EOI) signal to the hardware, for example but not limited, it may writes to an EOI register of the corresponding local interrupt controller of a CPU core. Moreover, an interrupt send from one CPU core to the other CPU core is called an inter-processor interrupt (IPI).
A transition from guest mode to host mode is called a VM exit and the transition from host mode to guest mode is a VM entry. The performance overhead of a VM exit/entry lies in the cycles spent in saving and restoring execution contexts and the associated pollution of CPU caches when executing hypervisor code. Some of the existing architecture, such as x86 server architecture, dictates that either every external interrupt causes a VM exit or none of the external interrupts causes a VM exit. This limitation makes it difficult to deliver an interrupt differently depending on whether its target VM is currently running or not.
With increasingly sophisticated hardware support for virtualization, the performance overhead due to I/O virtualization emerged gradually. Therefore, the advent of SR-IOV (Single Root I/O Virtualization), MR-IOV (Multi-Root I/O Virtualization) and para-virtualization allows a VM to reduce the DMA-related virtualization overhead. Nevertheless, in general frequent context switching, such as VM exit/entry during interrupt delivery, incurs significant portion of I/O virtualization performance overhead.
The hypervisor is able to inject a virtual interrupt into a VM only when the hypervisor and the VM both run on the same CPU core. For emulated virtual devices, this causes a VM exit for every interrupt from a back-end driver to one of its associated front-end drivers, because these drivers tend to run on different CPU cores. Also existing mechanisms for timer interrupt delivery trigger VM exits to the hypervisor.
To reduce the number of VM exits, some hardware vendors are pursuing hardware virtualization support for the interrupt controller. A research proposes a binary rewriting technique to reduce the number of VM exits. This mechanism dynamically optimizes the VM's code by identifying instruction pairs that cause consecutive VM exits and dynamically translating the guest code to a variant that incurs fewer VM exits. Another research eliminates VM exits by pre-allocating each resource and para-virtualizing the guest. There is also a mechanism sets a designated system call to enter a real-time mode operation and based on various setting of data structures to reduce the VM exits.